package com.ouyy.volunteerservice.volunteer.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ouyy.volunteerservice.volunteer.domain.po.QuestionAnswers;
import com.ouyy.volunteerservice.volunteer.service.questionAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/questionAnswer")
public class QuestionAnswerController {

    @Autowired
    private questionAnswerService questionAnswerService;

    @GetMapping("/{id}")
    public List<QuestionAnswers> getQuestionAnswersById(@PathVariable Long id) {
        QueryWrapper<QuestionAnswers> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",id);
        return questionAnswerService.list(queryWrapper);
    }



    @GetMapping("/getAll")
    public List<QuestionAnswers> getAllQuestionAnswers() {
        // 使用 MyBatis-Plus 的 list() 方法获取所有记录
        return questionAnswerService.list();
    }

    @PostMapping
    public void addQuestionAnswer(@RequestBody QuestionAnswers questionAnswer) {
        questionAnswerService.save(questionAnswer);
    }

    @PutMapping("/update")
    public void updateQuestionAnswer(@RequestBody QuestionAnswers questionAnswer) {
        questionAnswerService.updateById(questionAnswer);
    }

    @DeleteMapping("/{id}")
    public void deleteQuestionAnswer(@PathVariable Long id) {
        questionAnswerService.removeById(id);
    }
}